package com.newworld.basketballfire.main.impl;

import com.newworld.basketballfire.main.bean.UserListParam;
import com.newworld.basketballfire.main.business.UserBusiness;
import com.newworld.basketballfire.main.utils.CommonUtils;
import com.newworld.basketballfire.service.delegate.UserServiceDelegate;
import com.newworld.basketballfire.service.exception.ServiceException;
import com.newworld.basketballfire.service.model.ListResult;
import com.newworld.basketballfire.service.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by George on 2019/3/3.
 * UserServiceDelegateImpl
 */
@Component
public class UserServiceDelegateImpl implements UserServiceDelegate {

    @Autowired
    private UserBusiness userBusiness;

    @Override
    public User createUser(User user) throws ServiceException {
        return userBusiness.createUser(user);
    }

    @Override
    public User updateUser(String id, User user) throws ServiceException {
        user.setId(id);
        return userBusiness.updateUser(user);
    }

    @Override
    public User getUser(String id) throws ServiceException {
        return userBusiness.getUser(id);
    }

    @Override
    public ListResult<User> getUserList(String name, int pageNo, int pageSize) throws ServiceException {
        int curIndex = CommonUtils.getCurIndex(pageNo, pageSize);
        UserListParam userListParam = new UserListParam(name, pageNo, pageSize, curIndex);
        return userBusiness.getUserList(userListParam);
    }

}
